<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class CreateUser extends Request {

	/**
	 * Determine if the user is authorized to make this request.
	 * @return bool
	 */
	public function authorize() {
		return true;
	}

	/**
	 * Get the validation rules that apply to the request.
	 * @return array
	 */
	public function rules() {
		return [
			'type'        => 'required',
			'mobile'      => ['required_if:type,mobile', 'regex:/^[0-9]{11}$/', 'unique:users,mobile'],
			'name'        => ['required', 'regex:/^[\x{4e00}-\x{9fa5}|\w]{2,18}$/u', 'unique:users,name'],
			'password'    => 'required|between:6,20|alpha_dash',
		];
	}

	/**
	 * 自定义验证信息
	 * @return array
	 */
	public function messages() {
		return [
			'mobile.type'          => '请选择注册类型',
			'mobile.required'      => '请填写手机号码',
			'mobile.regex'         => '手机号码格式不正确',
			'mobile.unique'        => '此号码已被使用',
			'mobile_code.unique'   => '请填写验证码',
			'name.required'        => '请填写昵称',
			'name.regex'           => '昵称必须为2-18位中英文、数字及下划线',
			'name.unique'          => '该昵称已被占用',
			'password.required'    => '请填写密码',
			'password.between'     => '密码必须在6-20个字符之间',
			'password.alpha_dash'  => '密码只允许字母、数字、破折号（-）以及下划线（_）',

		];
	}
}
